using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public static class SoundTools
    {
        private static readonly Dictionary<SoundType, AudioClip> map;

        static SoundTools()
        {
            var settings = LoadSettings();
            map = new Dictionary<SoundType, AudioClip>();
            for (var i = 0; i < settings.SoundItems.Length; i++)
                map.Add(settings.SoundItems[i].key, settings.SoundItems[i].value);
        }

        private static SoundSettings LoadSettings()
        {
            var loadedSettings = (SoundSettings)Resources.Load("SoundSettings", typeof(SoundSettings));
            if (loadedSettings == null)
            {
                loadedSettings = ScriptableObject.CreateInstance<SoundSettings>();
                Debug.LogError("ReplaceSettings is not exist (Resources)");
            }

            return loadedSettings;
        }

        public static AudioClip Get(SoundType key)
        {
            if (map.ContainsKey(key)) return map[key];
            return null;
        }
    }
}